﻿<UserControl x:Class="Oxage.Printing.Views.PrintView"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:v="clr-namespace:Oxage.Printing.Views"
	xmlns:m="clr-namespace:Oxage.Printing.Models"
	xmlns:common="clr-namespace:Oxage.Common">
	<UserControl.Resources>
    <ResourceDictionary x:Name="theme">
			<!--
      <ResourceDictionary.MergedDictionaries>
				<ResourceDictionary Source="../Resources/ExpressionTheme.xaml" />
				<ResourceDictionary Source="../Resources/Styles.xaml" />
			</ResourceDictionary.MergedDictionaries>
      -->
		</ResourceDictionary>
	</UserControl.Resources>
	<UserControl.DataContext>
		<m:PrintViewModel />
	</UserControl.DataContext>
	<Grid x:Name="LayoutRoot">
		<Grid.Resources>
			<common:VisibilityConverter x:Key="VisibilityConverter" />
			<common:RadioButtonConverter x:Key="RadioButtonConverter" />
		</Grid.Resources>

		<ScrollViewer Margin="0" Padding="0" BorderThickness="0" VerticalScrollBarVisibility="Auto">
			<StackPanel MinWidth="220" CanVerticallyScroll="True" CanHorizontallyScroll="False">
				<!-- Instructions -->
				<Border Background="#595959" CornerRadius="0,3,3,3" Margin="0,0,0,2">
					<StackPanel Orientation="Vertical" Margin="6">
						<TextBlock Foreground="White">
							<Run>Print a xaml document. Visit </Run>
							<Hyperlink NavigateUri="http://xbprint.codeplex.com" FontSize="11" TargetName="_blank" Command="{Binding HyperlinkCommand}" CommandParameter="http://xbprint.codeplex.com">http://xbprint.codeplex.com</Hyperlink>
						</TextBlock>
						<Grid Visibility="{Binding HasError, Converter={StaticResource VisibilityConverter}}">
							<TextBlock Text="{Binding LastError.Message}" ToolTipService.ToolTip="{Binding LastError.StackTrace}" Foreground="Red" />
						</Grid>
					</StackPanel>
				</Border>

				<!-- Margins -->
				<Border Background="#595959" CornerRadius="3" Margin="0,0,0,2">
					<StackPanel Margin="4">
						<TextBlock Text="Margins" Style="{DynamicResource HeaderTextStyle}" />
						<Grid>
							<Grid.RowDefinitions>
								<RowDefinition Height="Auto" />
								<RowDefinition Height="Auto" />
							</Grid.RowDefinitions>
							<Grid.ColumnDefinitions>
								<ColumnDefinition Width="65" />
								<ColumnDefinition Width="*" />
								<ColumnDefinition Width="65" />
								<ColumnDefinition Width="*" />
							</Grid.ColumnDefinitions>

							<TextBlock Grid.Row="0" Grid.Column="0" Text="Top" Foreground="White" HorizontalAlignment="Right" Margin="0,0,4,0" VerticalAlignment="Center" />
							<TextBlock Grid.Row="1" Grid.Column="0" Text="Left" Foreground="White" HorizontalAlignment="Right" Margin="0,0,4,0" VerticalAlignment="Center" />
							<TextBlock Grid.Row="0" Grid.Column="2" Text="Bottom" Foreground="White" HorizontalAlignment="Right" Margin="0,0,4,0" VerticalAlignment="Center" />
							<TextBlock Grid.Row="1" Grid.Column="2" Text="Right" Foreground="White" HorizontalAlignment="Right" Margin="0,0,4,0" VerticalAlignment="Center" />

							<TextBox Grid.Row="0" Grid.Column="1" TabIndex="0" Text="{Binding MarginTop, Mode=TwoWay}" Margin="0,2,0,2" VerticalAlignment="Center" common:TextBoxInstantBindingUpdate.IsEnabled="True" />
							<TextBox Grid.Row="1" Grid.Column="1" TabIndex="1" Text="{Binding MarginLeft, Mode=TwoWay}" Margin="0,2,0,2" VerticalAlignment="Center" common:TextBoxInstantBindingUpdate.IsEnabled="True" />
							<TextBox Grid.Row="0" Grid.Column="3" TabIndex="2" Text="{Binding MarginBottom, Mode=TwoWay}" Margin="0,2,0,2" VerticalAlignment="Center" common:TextBoxInstantBindingUpdate.IsEnabled="True" />
							<TextBox Grid.Row="1" Grid.Column="3" TabIndex="3" Text="{Binding MarginRight, Mode=TwoWay}" Margin="0,2,0,2" VerticalAlignment="Center" common:TextBoxInstantBindingUpdate.IsEnabled="True" />
						</Grid>
					</StackPanel>
				</Border>

				<!-- Orientation -->
				<Border Background="#595959" CornerRadius="3" Margin="0,0,0,2">
					<StackPanel Margin="4">
						<TextBlock Text="Orientation" Style="{DynamicResource HeaderTextStyle}" />
						<StackPanel Orientation="Horizontal">
							<!-- Portrait -->
							<StackPanel Orientation="Vertical" Margin="0,0,4,0">
								<Grid Width="50" Height="50">
									<RadioButton x:Name="rbPortrait" Width="38" Height="50" TabIndex="14" IsChecked="{Binding Orientation, Converter={StaticResource RadioButtonConverter}, ConverterParameter='Portrait'}" GroupName="Orientation" Style="{DynamicResource OrientationRadioButtonStyle}" HorizontalAlignment="Center" VerticalAlignment="Center" Background="#777777" BorderBrush="LightBlue">
										<Border Width="38" Height="50" Background="White">
											<TextBlock Text="A" FontSize="18" Foreground="Black" FontWeight="Bold" TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" />
										</Border>
									</RadioButton>
								</Grid>
								<TextBlock Text="Portrait" Foreground="White" TextAlignment="Center" Visibility="{Binding IsChecked, ElementName=rbPortrait, Converter={StaticResource VisibilityConverter}, ConverterParameter='Invert'}" />
								<TextBlock Text="Portrait" Foreground="LightBlue" TextAlignment="Center" Visibility="{Binding IsChecked, ElementName=rbPortrait, Converter={StaticResource VisibilityConverter}}" />
							</StackPanel>

							<!-- Landscape -->
							<StackPanel Orientation="Vertical" Margin="0,0,4,0">
								<Grid Width="50" Height="50">
									<RadioButton x:Name="rbLandscape" Width="50" Height="36" TabIndex="15" IsChecked="{Binding Orientation, Converter={StaticResource RadioButtonConverter}, ConverterParameter='Landscape'}" GroupName="Orientation" Style="{DynamicResource OrientationRadioButtonStyle}" HorizontalAlignment="Center" VerticalAlignment="Center" Background="#777777" BorderBrush="LightBlue">
										<Border Width="50" Height="36" Background="White">
											<TextBlock Text="A" FontSize="18" Foreground="Black" FontWeight="Bold" TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" />
										</Border>
									</RadioButton>
								</Grid>
								<TextBlock Text="Landscape" Foreground="White" TextAlignment="Center" Visibility="{Binding IsChecked, ElementName=rbLandscape, Converter={StaticResource VisibilityConverter}, ConverterParameter='Invert'}" />
								<TextBlock Text="Landscape" Foreground="LightBlue" TextAlignment="Center" Visibility="{Binding IsChecked, ElementName=rbLandscape, Converter={StaticResource VisibilityConverter}}" />
							</StackPanel>
						</StackPanel>
					</StackPanel>
				</Border>

				<!-- Stretch -->
				<Border Background="#595959" CornerRadius="3" Margin="0,0,0,2">
					<StackPanel Margin="4">
						<TextBlock Text="Alignment" Style="{DynamicResource HeaderTextStyle}" />
						<Grid>
							<Grid.RowDefinitions>
								<RowDefinition Height="Auto" />
								<RowDefinition Height="Auto" />
								<RowDefinition Height="Auto" />
							</Grid.RowDefinitions>
							<Grid.ColumnDefinitions>
								<ColumnDefinition Width="65" />
								<ColumnDefinition Width="*" />
							</Grid.ColumnDefinitions>

							<TextBlock Grid.Row="0" Grid.Column="0" Text="Stretch" Foreground="White" Margin="0,0,4,0" HorizontalAlignment="Right" VerticalAlignment="Center" />
							<ComboBox Grid.Row="0" Grid.Column="1" TabIndex="20" ItemsSource="{Binding StretchList}" SelectedItem="{Binding StretchType, Mode=TwoWay}" Margin="0,2,0,2" VerticalAlignment="Center" />

							<TextBlock Grid.Row="1" Grid.Column="0" Text="Vertical" Foreground="White" Margin="0,0,4,0" HorizontalAlignment="Right" VerticalAlignment="Center" />
              <ComboBox Grid.Row="1" Grid.Column="1" TabIndex="20" ItemsSource="{Binding VerticalAlignmentList}" SelectedItem="{Binding VerticalAlignmentType, Mode=TwoWay}" Margin="0,2,0,2" VerticalAlignment="Center" />

							<TextBlock Grid.Row="2" Grid.Column="0" Text="Horizontal" Foreground="White" Margin="0,0,4,0" HorizontalAlignment="Right" VerticalAlignment="Center" />
              <ComboBox Grid.Row="2" Grid.Column="1" TabIndex="20" ItemsSource="{Binding HorizontalAlignmentList}" SelectedItem="{Binding HorizontalAlignmentType, Mode=TwoWay}" Margin="0,2,0,2" VerticalAlignment="Center" />
						</Grid>
					</StackPanel>
				</Border>

				<!-- Paper size -->
				<Border Background="#595959" CornerRadius="3" Margin="0,0,0,2">
					<StackPanel Margin="4">
						<TextBlock Text="Paper size" Style="{DynamicResource HeaderTextStyle}" />
						<Grid>
							<Grid.RowDefinitions>
								<RowDefinition Height="Auto" />
								<RowDefinition Height="Auto" />
								<RowDefinition Height="Auto" />
							</Grid.RowDefinitions>
							<Grid.ColumnDefinitions>
								<ColumnDefinition Width="65" />
								<ColumnDefinition Width="*" />
							</Grid.ColumnDefinitions>

							<TextBlock Grid.Row="0" Grid.Column="0" Text="Format" Foreground="White" Margin="0,0,4,0" HorizontalAlignment="Right" VerticalAlignment="Center" />
							<ComboBox Grid.Row="0" Grid.Column="1" TabIndex="30" ItemsSource="{Binding PaperFormatList}" SelectedItem="{Binding PaperFormat, Mode=TwoWay}" Margin="0,2,0,2" VerticalAlignment="Center" />

							<TextBlock Grid.Row="1" Grid.Column="0" Text="Width" Foreground="White" Margin="0,0,4,0" HorizontalAlignment="Right" VerticalAlignment="Center" />
							<TextBox Grid.Row="1" Grid.Column="1" TabIndex="31" Text="{Binding PaperWidth, Mode=TwoWay}" Margin="0,2,0,2" VerticalAlignment="Center" common:TextBoxInstantBindingUpdate.IsEnabled="True" />

							<TextBlock Grid.Row="2" Grid.Column="0" Text="Height" Foreground="White" Margin="0,0,4,0" HorizontalAlignment="Right" VerticalAlignment="Center" />
							<TextBox Grid.Row="2" Grid.Column="1" TabIndex="32" Text="{Binding PaperHeight, Mode=TwoWay}" Margin="0,2,0,2" VerticalAlignment="Center" common:TextBoxInstantBindingUpdate.IsEnabled="True" />
						</Grid>
					</StackPanel>
				</Border>

				<!-- Buttons -->
				<Border Background="#595959" CornerRadius="3" Margin="0,0,0,2">
					<StackPanel Margin="4" Orientation="Horizontal">
						<Button Content="Load" Command="{Binding LoadCommand}" TabIndex="40" Padding="7,4,7,4" Cursor="Hand" HorizontalAlignment="Left" Margin="0,0,4,0" VerticalAlignment="Center" Visibility="{Binding IsStandalone, Converter={StaticResource VisibilityConverter}}" />
						<Button Content="Print" Command="{Binding PrintCommand}" TabIndex="41" Padding="7,4,7,4" Cursor="Hand" BorderThickness="2" HorizontalAlignment="Left" Margin="0,0,4,0" VerticalAlignment="Center" IsEnabled="{Binding CanPrint}" />
						<Button Content="Refresh" Command="{Binding RefreshCommand}" TabIndex="42" Padding="7,4,7,4" Cursor="Hand" HorizontalAlignment="Left" Margin="0,0,4,0" VerticalAlignment="Center" IsEnabled="{Binding CanPrint}" Visibility="{Binding IsDebug, Converter={StaticResource VisibilityConverter}}" />
						<Button Content="Debug" Command="{Binding DebugCommand}" TabIndex="43" Padding="7,4,7,4" Cursor="Hand" HorizontalAlignment="Left" Margin="0,0,4,0" VerticalAlignment="Center" IsEnabled="{Binding CanPrint}" Visibility="{Binding IsDebug, Converter={StaticResource VisibilityConverter}}" />
					</StackPanel>
				</Border>

				<!-- Preview -->
				<Border Background="#595959" CornerRadius="3" Margin="0,0,0,2">
					<StackPanel Margin="4">
						<TextBlock Text="Preview" Style="{DynamicResource HeaderTextStyle}" />
						<Border x:Name="Preview" ClipToBounds="True" Margin="0,2,0,0" CornerRadius="3">
							<Border.Background>
								<VisualBrush ViewportUnits="Absolute" Viewport="0,0,25,25" TileMode="Tile">
									<VisualBrush.Visual>
										<Grid Width="16" Height="16" Background="#FF2A2A2A">
											<Rectangle Width="8" Height="8" Fill="#FF2D2D2D" VerticalAlignment="Top" HorizontalAlignment="Left" />
											<Rectangle Width="8" Height="8" Fill="#FF2D2D2D" VerticalAlignment="Bottom" HorizontalAlignment="Right" />
										</Grid>
									</VisualBrush.Visual>
								</VisualBrush>
							</Border.Background>

							<Viewbox Stretch="Uniform" Margin="4" MaxHeight="250">
								<Border BorderBrush="#777777" BorderThickness="0" Background="#EEEEEE" Width="{Binding PreviewPaperWidth}" Height="{Binding PreviewPaperHeight}">
									<Border Background="White" BorderBrush="#777777" BorderThickness="0" Margin="{Binding PreviewMargin}">
										<Border Background="{Binding PreviewBrush}">
											<!-- Preview is rendered as a container background (using VisualBrush) -->
										</Border>
									</Border>
								</Border>
							</Viewbox>
						</Border>
					</StackPanel>
				</Border>

				<!-- Debug -->
				<Border Background="#595959" CornerRadius="3" Margin="0,0,0,2" Visibility="{Binding Debug, Converter={StaticResource VisibilityConverter}}">
					<Grid Margin="4">
						<Grid.RowDefinitions>
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
						</Grid.RowDefinitions>
						<TextBlock Grid.Row="0" Text="Debug" Style="{DynamicResource HeaderTextStyle}" />
						<Border Grid.Row="1" ClipToBounds="True" Margin="0,2,0,0" CornerRadius="3">
							<TextBox Text="{Binding DebugMessage}" AcceptsReturn="True" TabIndex="51" Background="#444444" Foreground="White" FontFamily="Consolas" FontSize="10pt" IsReadOnly="True" HorizontalScrollBarVisibility="Auto" />
						</Border>
					</Grid>
				</Border>

			</StackPanel>
		</ScrollViewer>

	</Grid>
</UserControl>
